#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
路径检测调试脚本 v2
"""

import sys
import os
from pathlib import Path

def debug_path_detection():
    """调试路径检测逻辑"""
    print("=== 路径检测调试 ===")
    
    # 模拟打包环境
    print(f"sys.frozen: {getattr(sys, 'frozen', False)}")
    print(f"sys.executable: {sys.executable}")
    
    # 获取当前exe文件所在目录
    if getattr(sys, 'frozen', False):
        # 打包后的exe环境 - exe文件所在目录
        current_dir = Path(sys.executable).parent
        print(f"打包环境 - current_dir: {current_dir}")
    else:
        # 开发环境 - 当前脚本目录
        current_dir = Path(__file__).parent
        print(f"开发环境 - current_dir: {current_dir}")
    
    print(f"current_dir 绝对路径: {current_dir.resolve()}")
    print(f"current_dir 是否存在: {current_dir.exists()}")
    
    # 检查部署包环境
    is_deployment = 'deployments' in str(current_dir)
    print(f"是否为部署包环境: {is_deployment}")
    
    # 查找候选文件
    exe_candidates = [
        "wms_service.exe",
        "wms_sample.exe", 
        "main.exe",
        "wms_simple.exe"
    ]
    
    print(f"\n=== 在当前目录查找exe文件 ===")
    for exe_name in exe_candidates:
        exe_path = current_dir / exe_name
        exists = exe_path.exists()
        print(f"{exe_name}: {exe_path} -> 存在: {exists}")
        if exists:
            print(f"  绝对路径: {exe_path.resolve()}")
            print(f"  字符串路径: {str(exe_path.resolve())}")
    
    # 列出当前目录的所有文件
    print(f"\n=== 当前目录所有文件 ===")
    try:
        for item in current_dir.iterdir():
            if item.is_file():
                print(f"文件: {item.name}")
            elif item.is_dir():
                print(f"目录: {item.name}/")
    except Exception as e:
        print(f"列出目录内容失败: {e}")
    
    # 检查工作目录
    print(f"\n=== 工作目录信息 ===")
    print(f"Path.cwd(): {Path.cwd()}")
    print(f"os.getcwd(): {os.getcwd()}")

if __name__ == '__main__':
    debug_path_detection() 